<!DOCTYPE html>
<html>
<head>
    {include file='public/meta'/}

    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/core.css?v=5"/>


    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/setcard.css"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/css/setyxhd.css?v=7"/>
    <link rel="stylesheet" type="text/css" href="__STATIC_URL__/static/fonts/css/font-awesome.css?v=7"/>

    <link rel="stylesheet" href="__STATIC_URL__/static/css/bootstrapSwitch.css">
    <link rel="stylesheet" href="__STATIC_URL__/static/css/setcard.css"/>


    <script src="__STATIC_URL__/static/js/bootstrapSwitch.js"></script>

    <style>
        .ng-scope input {
            width: 232px;
            margin-left: 5px;
            opacity: 1;
        }
        #img{
            opacity: 0;
        }
        .img {
            width: 318px;
            height: 203px;
            display: inline-block;
            background-size: 100%;
        }
        .ng-scope input {
            width: 423px;

        }
        .form-control{
            width: 423px;
        }
    </style>
</head>
<body>
{include file='public/header'/}
<!------------------导航-------------------------->
<section>
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">

        <div class="panel">
            <div class="">
                <!--路径导航-->
                <ol class="breadcrumb">
                    <li>当前位置是&nbsp;:</li>
                    <li><a href="javascript:history.back();">营销工具</a></li>
                    <li><a href="javascript:history.back(-1)">活动营销</a></li>

                    <li class="active" style="color: #02b87f;">关注有礼设置</li>
                </ol>
                <div>
                    <div class="panel panel-default ng-scope">
                        <div class="panel-heading">
                            关注有礼设置规则列表
                        </div>
                        <div class="panel-body">
                            <div class="alert alert-success" style="background-color: rgba(204, 228, 223, 0.3);margin-top: 10px;margin-bottom: 20px;">
                                1.若发放类型为自定义链接 请忽略
                                <strong>
                                    <i class="ti-info-alt"> 发放数量及领取数量</i>
                                </strong>
                                字段
                            </div>
                            <table class="table table-bordered">
                                <thead>
                                <tr>
                                    <td>编号</td>
                                    <td>标题</td>
                                    <td>开始时间</td>
                                    <td>结束时间</td>
                                    <td>发放类型</td>
                                    <td>内容</td>
                                    <td>积分</td>
                                    <td>发放数量</td>
                                    <td>领取数量</td>
                                    <td>创建时间</td>
                                    <td>当前状态</td>
                                    <td class="text-center">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="vor"}
                                <tr ng-if="!instances.list.length" class="ng-scope">
                                    <td>{$vor.id}</td>
                                    <td>{$vor.title}</td>
                                    <td>{$vor.starttime|date="Y-m-d ",###}</td>
                                    <td>{$vor.endtime|date="Y-m-d ",###}</td>

                                    {if condition="$vor['type'] eq 3"}
                                    <td>自定义链接</td>
                                    <td>{$vor['url']}</td>

                                    {else}
                                    <td>送券</td>

                                    <td>{:getpaygive($vor['cardlist'])}</td>
                                    {/if}
                                    <td>{$vor.bonus}</td>
                                    <td>{$vor.num}</td>

                                    <td><a class="btn-link" href="{:url('marke/followputlog',['fid'=>$vor['id']])}">{$vor.get_num}</a></td>
                                    <td>{$vor.addtime|date="Y-m-d ",###}</td>
                                    <td>{if condition="$vor['status']=='1' "}已开启{else/}已关闭{/if}</td>
                                    <td>
                                        <a class="btn-link" href="{:url('marke/followputstatu',['id'=>$vor['id']])}">
                                            {switch name="vor.status"}
                                            {case value="1"}已开启{/case}
                                            {case value="0"}已关闭{/case}
                                            {default /}未知
                                            {/switch}
                                        </a>

                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="panel panel-default ng-scope c_content">

                        <form action="" method="post" id="creatcards">

                            <div class="headings gengduoxian">
                                <i class="infoLine"></i>关注有礼设置规则 <span class="note-inf">带<a style="color:red;"> * </a>为必填项</span>
                            </div>


                            <div class="panel-body">
                                <div class="alert alert-success" style="background-color: rgba(204, 228, 223, 0.3);margin-top: 10px;margin-bottom: 20px;">
                                    <strong>
                                        <i class="ti-info-alt"></i>
                                    </strong>
                                    <p>1.需要先行在营销工具中创建开启关注有礼免费券后，方可在本功能中选择已创建好的免费券。</p>
                                    <p>2.自定义链接即点击图文消息打开填写的网址</p>
                                </div>
                                <div class="row">
                                    <div class="col-sm-6">
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>标题：</label>
                                                <div class="col-sm-10">
                                                    <input type="hidden" name="id"   value="{$info['id']}" >
                                                    <input type="text" name="title" id="title" class="form-control" maxlength="12" required placeholder="" value="{$info['title']}" />
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>发放数量：</label>
                                                <div class="col-sm-10">
                                                    <input type="text" name="num" class="form-control"  required placeholder="" value="{$info['num']}" />
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-label="选择时间"
                                             data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>选择时间：</label>
                                                <div class="col-sm-10">
                                                    <div class=" w60">
                                                        <input type="text" name="times" class="form-control data_ipt" value="{$info['times']}"
                                                               placeholder="请选择开始时间-结束时间" disabled id="starttime" style="width:60%">


                                                    </div>

                                                    <div class="checkbox checkbox-primary permanent"
                                                         style="left: 41px;top: 4px;display: inline-block;">
                                                        <input type="hidden" name="time_type" value="{$info['time_type']}" id="lasting">
                                                        <input id="permanent_ck" type="checkbox"
                                                               class="autoDelayFlag" checked>
                                                        <label for="permanent_ck">永久有效</label>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>发放类型：</label>
                                                <div class="col-sm-10">
                                                    <select name="type" id="types" onchange="gradeChange(this)" class="form-control" required>
                                                        <option value="">请选择</option>

                                                        <option  {eq name="info['type']"  value="2"} selected {/eq} value="2">送券</option>
                                                        <option  {eq name="info['type']"  value="3"} selected {/eq} value="3">自定义链接</option>

                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" id="a_url">
                                            <div class="form-horizontal" data-label="自定义链接"
                                                 data-layout="horizontal">
                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>自定义链接：</label>
                                                    <div class="col-sm-10">
                                                        <input type="text" name="url" class="form-control" id="url" value="{$info['url']}">
                                                        <div class="r-message text-danger"></div>
                                                    </div>
                                                </div>
                                            </div>

                                        </div>

                                        <div class="form-horizontal" data-layout="horizontal" id="a_quan">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>选择卡券：</label>
                                                <div class="col-sm-10">
                                                    <select name="free_id" id="free_id" class="form-control" >
                                                        <option value="">请选择</option>
                                                        {volist name="freecard" id="vo"}
                                                        <option   {eq name="$info['free_id']" value="$vo['id']"}selected{/eq} value="{$vo['id']}">{$vo['title']}</option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>活动奖品：</label>
                                                <div class="col-sm-10">

                                                    <div style=" margin-top:3px;">
                                                        <div class="checkbox checkbox-info checkbox-inline prize">
                                                            <input type="hidden" id="iscards"  value="Y" name="is_cards">

                                                            <input type="hidden" id="isbonus"  value="{$info['is_bonus']}" name="is_bonus">
                                                            <input type="checkbox" id="bonus"  class="gift-input" >
                                                            <label for="bonus"> 赠送积分 </label>
                                                            <span class="container" style="display:none;">
    							                                <div class="col-md-6 pannel charge-rule-box"
                                                                     style="float:none;margin-top:10px;margin-left: -22px;width: 400px;">

                                                                    <div style="margin-top:10px;" class="gift-record">

    											                          <input type="number"
                                                                                 class="form-control prize-gift" min="1"
                                                                                 onkeyup="this.value=this.value.replace(/\D/g,&#39;&#39;)"
                                                                                 style="width: 80px;margin-left: 3px;display: inline-block;"
                                                                                 placeholder="请填写" name="bonus" value="{$info['bonus']}">
                                                                          <span style=" margin-left: 75px;line-height:38px;">积分</span>
                                                                          <a href="javascript:void(0);"
                                                                             class="del-charge-btn"
                                                                             style="display:none;"><i
                                                                                  class="icon-close"></i>
                                                                          </a>
                                                                    </div>
    							                				</div>
    								                         </span>
                                                        </div>



                                                    </div>

                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>描述内容：</label>
                                                <div class="col-sm-10">
                                                    <textarea name="description" id="description" style="width: 423px; padding: 10px;height: 133px;" required class="commodityIntro p_clear" >{$info['description']}</textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>图片：</label>
                                                <div class="col-sm-10">
                                                    <img  {empty  name="$info['img']"} src="__STATIC_URL__/static/images/commodityImg.png" {else/} src="{$info['img']}" {/empty} alt="商品图片" class="img">
                                                    <div class="ng-scope" style="position: relative;">
                                                        <span class="btn btn-default">上传图片</span>
                                                        <input type="file" id="img" value=""  onchange="upload('img','file')"/>
                                                        <input type="hidden" name="img" id="logopic-upload" required  value="{$info['img']}" >

                                                    </div>
                                                    <div class="r-desc ng-binding ng-scope"> 图片建议尺寸：750像素*480像素，格式为.jpg，大小不超过2M.</div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-horizontal" data-layout="horizontal">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label"><span class="red-xing-rs"></span>活动状态：</label>
                                                <div class="col-sm-10">
                                                    <input type="hidden" name="status" value="{$info['status']}" id="status" >
                                                    <div class="switch" id="give" data-animated="true">
                                                        <input type="checkbox" {if condition="$info['status'] eq '1' "}checked{/if}/>

                                                    </div>

                                                </div>
                                            </div>
                                        </div>


                                    </div>
                                </div>
                                <div class="alert alert-danger"
                                     style="margin:0;">每类规则只能同时存在一个
                                </div>
                            </div>
                            <div class="panel-footer">
                                <button class="btn btn-success" type="button" onclick="check();">保存</button>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
<script src="__STATIC_URL__/static/laydate/laydate.js"></script>
<script src="__STATIC_URL__/static/js/setyxhd.js?v=2"></script>
<script>


    laydate.render({
        elem: '#starttime',
        type: 'datetime',
        range:'-',

        change: function(value, date,endDate){ //监听日期被切换


        }
    });
    $(function(){
        var permanent_ck="{$info['time_type']}";
        if(permanent_ck==""){
            $("#permanent_ck").prop("checked", true)
        }
        if(permanent_ck=="range"){
            $(".data_ipt").removeAttr("disabled");
            $("#permanent_ck").prop("checked", false)
        }else if(permanent_ck=="lasting"){
            $(".data_ipt").attr("disabled", "disabled");
            $("#permanent_ck").prop("checked", true)
        }
        var is_bonus="{$info['is_bonus']}";
        var $bonus = $("#bonus").parent().find(".container");
        var is_cards="{$info['is_cards']}";
        var $cards = $("#cards").parent().find(".container");
        if(is_bonus=="Y"){
            $("#bonus").prop("checked", true)
            $bonus.show();
        }
        if(is_cards=="Y"){
            $("#cards").prop("checked", true)
            $cards.show();
        }
    })
</script>
<script>
    $(function () {
        var a="{$info['type']}";
        if(a==2){
            $('#a_url').hide();
            $('#a_quan').show();
        }else if(a==3){
            $('#a_url').show();
            $('#a_quan').hide();
        }else{
            $('#a_url').hide();
            $('#a_quan').show();
        }

    })
    function gradeChange(obj){
        var s= $(obj).val();
        if(s==2){
            $('#a_url').hide();
            $('#a_quan').show();
        }else if(s==3){
            $('#a_url').show();
            $('#a_quan').hide();
        }
    }
    function check(){
        var logopic=$("#logopic-upload").val();
        var starttime=$("#starttime").val();
        var types=$("#types").val();
        var free_id=$("#free_id").val();
        var url=$("#url").val();





        if ($('#permanent_ck').prop("checked")==false) {
            if(starttime==""){
                alert('请选择时间！');
                return false;
            }
        }

        if(logopic==""){
            alert('请上传图片！');
            return false;
        }
        if(types==3){
            if(url==""){
                alert('请填写连接！');
                return false;
            }
        }else if(types==2){
            if(free_id==""){
                alert('请选择卡券！');
                return false;
            }
        }
        // 校验通过，全部都不相同

        $.ajax({
            url: "{:url('')}",
            type: "post",
            data: $("#creatcards").serialize(),
            success: function (data) {
                console.log(data);
                if(data.code==0){
                    layer.msg(data.message);
                    setTimeout(function(){
                        window.location.reload();

                    },1500)
                }else{
                    layer.msg(data.message);
                }
            }
        })

    }

</script>
<script>
    function upload(file, typed) {
        var formData = new FormData();
        formData.append('file', $('#' + file)[0].files[0]);
        formData.append('other', file);
        $.ajax({
            url: "{:url('uploads/upload')}",
            type: 'POST',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
        }).done(function (res) {
            console.log(res);
            if(res.code=="0"){
                //            左侧预览图背景
                $(".commodityImg").attr("src", res.pic);
//            右侧预览图片
                $(".img").attr("src", res.pic);
//            相应隐藏input传值
                $("#logopic-upload").val(res.pic);
            }else{
                layer.alert(res.message);
            }

            // $("." + file).attr("src", res.savapath).css("display", "block");
            // $(".file-" + file).val(res.other);
            // $("." + typed + "-" + file).val(res.other);
        }).fail(function (res) {
            alert("上传失败")
        });
    };
</script>
<script>
    $("#give").on('switch-change', function (e, data) {
        var $el = $(data.el), value = data.value;
        if(value==true){
            $("#status").val(1);
        }else{
            $("#status").val(0);
        }
    });
</script>
<script>
    function jf(val){
        if(val == '2'){
            $("#iptval").removeClass("hidden");
        }else{
            $("#iptval").addClass("hidden");
        }
    }

</script>
</body>

</html>
